﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using System.Text;

namespace Socket
{
    class Program
    {

        // socket 
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                uporaba();
                return;
            }


            System.Net.Sockets.TcpClient clientSocket = new System.Net.Sockets.TcpClient();

            try
            {
                Console.WriteLine("Zagon klienta: ");

                clientSocket.Connect("127.0.0.1", 9999);

                NetworkStream serverStream = clientSocket.GetStream();
                byte[] outStream = null;
                outStream = System.Text.Encoding.ASCII.GetBytes(string.Join(" ", args) + " ");
                serverStream.Write(outStream, 0, outStream.Length);
                serverStream.Flush();
                byte[] inStream = new byte[10025];
                serverStream.Read(inStream, 0, (int)clientSocket.ReceiveBufferSize);
                string returndata = System.Text.Encoding.ASCII.GetString(inStream);
                Console.WriteLine("Data from Server : " + returndata);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                Console.Read();
            }


        }

        static void uporaba()
        {
            Console.WriteLine("NEPRAVILNA UPORABA!");
            Console.WriteLine("");
            Console.WriteLine("  paralelno testiranje");
            Console.WriteLine("  --------------------");
            Console.WriteLine(" --positions   definiranje pozicij paralelnega testiranja, ločeno s podpičjem");
            Console.WriteLine("         --positions=COM1;COM2;COM3");
            Console.WriteLine(" Test start");
            Console.WriteLine("   socket_par.exe --serial=Z13049931G --position=COM3");
            Console.WriteLine(" Test stop");
            Console.WriteLine("");
            Console.WriteLine("   socket_par.exe --serial=Z13049931G --comment=\"Test_OK PASS\" --position=COM3 --status=START --auto");
            Console.WriteLine("     --serial    serijska številka");
            Console.WriteLine("     --comment   komentar testa");
            Console.WriteLine("     --position  pozicija testiranca");
            Console.WriteLine("     --status    PASS, FAIL ali START");
            Console.WriteLine("     --auto      avtomatski vpis v bazo");
            Console.WriteLine("  klasično testiranje");
            Console.WriteLine("   socket_par.exe Z13049931G \"Test je OK\"");
            Console.Read();
        }
    }
}
